import Vue from 'vue'
import Router from 'vue-router'
import livingInfo from '@/components/livingInfo'
import index from '@/components/peopleDaily/index'
import scope from '@/components/page/scope'
import api from '../api/api.js'
Vue.use(Router)

export default new Router({
	routes: [{
			path: "/",
			redirect: "/livingInfo"
		},
		{
			path: '/livingInfo/:id',
			name: 'livingInfo',
			component: livingInfo,
			beforeEnter(to, from, next) {
				var ua = window.navigator.userAgent.toLowerCase();
				let id = to.params.id
				if (ua.match(/MicroMessenger/i) == 'micromessenger') { //微信授权
					if (sessionStorage.getItem('scope') == 'false' || sessionStorage.getItem('scope') == null) {
						let url = api.getWXCode(id, "livingInfo")
						location.replace(url)
					} else {
						next()
					}
					return true;
				} else {
					next()
				}
			},
		},
		{
			path: '/index/:id',
			name: 'index',
			component: index,
			beforeEnter(to, from, next) {
				var ua = window.navigator.userAgent.toLowerCase();
				let id = to.params.id
				if (ua.match(/MicroMessenger/i) == 'micromessenger') {
					if (sessionStorage.getItem('scope') == 'false' || sessionStorage.getItem('scope') == null) {
						let url = api.getWXCode(id, "index")
						location.replace(url)
					} else {
						next()
					}
					return true;
				} else {
					next()
				}
			},
		},
		{
			path: '/scope/:id',
			name: 'scope',
			component: scope,
		}
	]
})
